﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;

using JM.JCY.Proxy;
using JM.JCY.BusinessEntity;
using JM.JCY.Common;
using NCS.IConnect.ApplicationContexts;

namespace JM.JCY.SharePointComponent.PhotoAlbum.AlbumCategories
{
    public partial class AlbumCategoriesUserControl : UserControl
    {
        public string appType
        {
            set;
            get;
        }
        public int appId
        {
            set;
            get;
        }
        public int _staffId
        {
            set;
            get;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadApplicationContext();
                PhotoAlbumSearchDataSet.T_AlbumDataTable AlbumDT = new PhotoAlbumSearchDataSet.T_AlbumDataTable();
                using (PhotoAlbumProxy proxy = new PhotoAlbumProxy())
                {
                    AlbumDT = proxy.GetAllPublicAlbums(JCYConstant.PhotoAlbum.ApplicationTypeName.PublicName, 0);
                    dlPublicAlbum.DataSource = AlbumDT.Select(string.Format("id<={0}", 4));
                    dlPublicAlbum.DataBind();

                    PhotoAlbumSearchDataSet.T_UserDepartmentDataTable department = proxy.GetUserDepartmentByUserId(_staffId);
                    dlWorkgroup.DataSource = department;
                    dlWorkgroup.DataBind();

                    PhotoAlbumSearchDataSet.T_UserCommitteeDataTable committee = proxy.GetUserCommitteeByUserId(_staffId);
                    DataListCommittee.DataSource = committee;
                    DataListCommittee.DataBind();

                    //AlbumDT = proxy.GetMySelfAlbums(JCYConstant.PhotoAlbum.ApplicationTypeName.PersonalName, _staffId, _staffId);
                    //dlMyContributions.DataSource = AlbumDT.Select(string.Format("id<={0}", 4));
                    //dlMyContributions.DataBind();
                }
            }
        }

        private void LoadApplicationContext()
        {
            _staffId = 11;
            if (ApplicationContext.Current.GetKeyValue("userId") != null)
            {
                _staffId = Convert.ToInt32(ApplicationContext.Current.GetKeyValue("userId"));
            }

            if (ApplicationContext.Current.GetKeyValue("appType") != null)
            {
                appType = ApplicationContext.Current.GetKeyValue("appType").ToString();
            }

            switch (appType)
            {
                case JCYConstant.PhotoAlbum.ApplicationTypeName.PublicName:
                    appId = 0;
                    break;
                case JCYConstant.PhotoAlbum.ApplicationTypeName.PersonalName:
                    appId = _staffId;
                    break;
                case JCYConstant.PhotoAlbum.ApplicationTypeName.WorkgroupName:
                    if (ApplicationContext.Current.GetKeyValue("AppId") != null)
                    {
                        appId = Convert.ToInt32(ApplicationContext.Current.GetKeyValue("AppId"));
                    }
                    break;
                case JCYConstant.PhotoAlbum.ApplicationTypeName.CommitteeName:
                    if (ApplicationContext.Current.GetKeyValue("AppId") != null)
                    {
                        appId = Convert.ToInt32(ApplicationContext.Current.GetKeyValue("AppId"));
                    }
                    break;
            }
        }

        protected void DateList_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            //Label lblContext = (Label)e.Item.FindControl("lblContext");
            //Image imgContext = (Image)e.Item.FindControl("imgContext");
            //new CommonFunctions().SetContextAndIcon(lblContext, imgContext, Convert.ToInt32(lblContext.Text.Trim()));
        }

        public string PartSubString(string fieldName, string fieldValue)
        {
            return fieldValue;
        }
    }
}
